package net.neocat.tcx.file;

/**
 * Created with IntelliJ IDEA.
 * User: jschek
 * Date: 4/24/13
 * Time: 11:40 PM
 * To change this template use File | Settings | File Templates.
 */
public class TrackPoint {
    private final long timestamp;
    private final GeoPosition position;
    private final double altitudeMeters;
    private final double distanceMeters;
    private transient boolean essential;
    private transient TrackPoint previous;

    public TrackPoint(long timestamp, GeoPosition position, double altitudeMeters, double distanceMeters) {

        this.timestamp = timestamp;
        this.position = position;
        this.altitudeMeters = altitudeMeters;
        this.distanceMeters = distanceMeters;
    }

    public boolean isEssential() {
        return essential;
    }

    public void setEssential(boolean essential) {
        this.essential = essential;
    }

    public TrackPoint getPrevious() {
        return previous;
    }

    public void setPrevious(TrackPoint previous) {
        this.previous = previous;
    }

    @Override
    public String toString() {
        return "TrackPoint{" +
                "timestamp=" + timestamp +
                ", position=" + position +
                ", altitudeMeters=" + altitudeMeters +
                ", distanceMeters=" + distanceMeters +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TrackPoint that = (TrackPoint) o;

        if (Double.compare(that.altitudeMeters, altitudeMeters) != 0) return false;
        if (Double.compare(that.distanceMeters, distanceMeters) != 0) return false;
        if (timestamp != that.timestamp) return false;
        if (position != null ? !position.equals(that.position) : that.position != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = (int) (timestamp ^ (timestamp >>> 32));
        result = 31 * result + (position != null ? position.hashCode() : 0);
        temp = Double.doubleToLongBits(altitudeMeters);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(distanceMeters);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

    public long getTimestamp() {

        return timestamp;
    }

    public GeoPosition getPosition() {
        return position;
    }

    public double getAltitudeMeters() {
        return altitudeMeters;
    }

    public double getDistanceMeters() {
        return distanceMeters;
    }

}
